package com.itheima.config;
/*
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
import com.alibaba.fastjson.JSON;*/
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;


/*@Configuration
public class SentinelConfig {

    public SentinelConfig() {

       *//* GatewayCallbackManager.setBlockHandler(new BlockRequestHandler() {

            @Override
            public Mono<ServerResponse> handleRequest(ServerWebExchange serverWebExchange, Throwable throwable) {
                ServerHttpResponse response = serverWebExchange.getResponse();
                response.getHeaders().add("Content-Type", "application/json");

                //设置返回json数据
                Map<String, String> map = new HashMap<>();
                map.put("code", "502");
                map.put("msg", "被限流了");

                System.out.println("SentinelConfig 流控.....");

                return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS)
                        .body(Mono.just(JSON.toJSONString(map)), String.class);*//*
            }
        });
    }

}*/
